package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysConsultants;
import com.hl.sfzy.entity.SysUser;
import com.hl.sfzy.pojo.FormDate;
import com.hl.sfzy.service.SysConsultantsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
public class SysConsultantsController {
    @Autowired
    private SysConsultantsService sysConsultantsService;
    /*
     * 新增
     * */
    @PostMapping("/sysConsultants")
    public Result add(@RequestBody SysConsultants sysConsultants){
        System.out.println("yyyyyy"+sysConsultants);
        int num = sysConsultantsService.add(sysConsultants);
        return num > 0 ? Result.success() : Result.error();
    }
    /*
     * 删除
     * */
    @DeleteMapping("/sysConsultants/{id}")
    public Result remove(@PathVariable("id") Integer id){
        int num = sysConsultantsService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }
    @DeleteMapping("/sysConsultants")
    public Result removeBatch(Integer[] ids){
        int num = sysConsultantsService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();

    }
    @PutMapping("/sysConsultants")
    public Result edit(@RequestBody SysConsultants sysConsultants){
        int num = sysConsultantsService.edit(sysConsultants);
        return num > 0 ? Result.success() : Result.error();
    }
    @GetMapping("/sysConsultants/{id}")
    public Result findById(@PathVariable("id") Integer id){
        SysConsultants byId = sysConsultantsService.findById(id);
        return Result.success(byId);
    }

    @GetMapping("/sysConsultants")
    public Result findAll(SysConsultants sysConsultants){
        List<SysConsultants> list = sysConsultantsService.find(sysConsultants);
        return Result.success(list);
    }

    @GetMapping("/sysConsultants/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysConsultants sysConsultants) {
        System.out.println("1="+sysConsultants);
        Map<String, Object> map = sysConsultantsService.findPage(pageNum, pageSize,sysConsultants);
        System.out.println(map);
        return Result.success(map);
    }
    @GetMapping("/sysConsultants/position/{status}")
    public Result findById(@PathVariable("status") String status){
        System.out.println();
        List<SysConsultants> byPosition = sysConsultantsService.findByPosition(status);
        return Result.success(byPosition);
    }


    @GetMapping("/sysConsultant/formDate")
    public  Result findByLeverName(FormDate formDate){
        List<FormDate> byLevelName = sysConsultantsService.findByLevelName(formDate);
        return Result.success(byLevelName);
    }
    @GetMapping("/sysConsultants/photo/{id}")
    public Result findByPhoto(@PathVariable("id") Integer id) {
        Integer byPhoto = sysConsultantsService.findByPhoto(id);
        return Result.success(byPhoto);
    }
    @GetMapping("/sysConsultants/info/{id}")
    public Result findInfo(@PathVariable("id") Integer id){
        SysConsultants consultant = sysConsultantsService.findInfo(id);
        return Result.success(consultant);

    }

}

